/**
 * File    : SiteManagerImpl.java
 * Created : 2008-10-10
 * By      : LuHuiguo
 */
package com.luhuiguo.sso.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import com.luhuiguo.sso.dao.SiteDao;
import com.luhuiguo.sso.entity.Site;
import com.luhuiguo.sso.service.SiteManager;

/**
 * @author LuHuiguo
 * @version $Id: SiteManagerImpl.java 9 2008-10-12 12:51:20Z LuHuiguo $
 * 
 */
@Transactional
public class SiteManagerImpl implements SiteManager {

	private SiteDao siteDao;

	@Required
	public void setSiteDao(SiteDao siteDao) {
		this.siteDao = siteDao;
	}

	@Override
	@Transactional(readOnly = true)
	public Site getSite(Long id) {
		return siteDao.get(id);
	}

	@Override
	@Transactional(readOnly = true)
	public Site getSite(String url) {
		List<Site> sites = siteDao.findByProperty("url", url); //$NON-NLS-1$
		if (sites.size() == 0) {
			return null;
		}
		return sites.get(0);
	}

	@Override
	public boolean existsSite(String url) {
		return getSite(url) != null;
	}

	@Override
	@Transactional(readOnly = true)
	public List<Site> getAllSite(int... rowStartIdxAndCount) {
		return siteDao.findAll(rowStartIdxAndCount);
	}

	@Override
	public void createSite(Site site) {
		siteDao.create(site);

	}

	@Override
	public void updateSite(Site site) {
		siteDao.update(site);
	}

	@Override
	public void deleteSite(Long id) {
		siteDao.delete(id);
	}

	@Override
	public void deleteSite(Site site) {
		siteDao.delete(site);
	}

	@Override
	public void deleteSite(String url) {
		deleteSite(getSite(url));
	}

}
